import { useEffect } from "react";
import { useLocation, useNavigate } from "react-router-dom";

function RoutGuard(Component: any) {
  const Newcomponent = () => {
    const { pathname } = useLocation();
    const navigate = useNavigate();
    const islogin = localStorage.getItem("username");
    useEffect(() => {
      if (!islogin && pathname !== "/login") {
        navigate("/login");
      }
    }, [pathname]);
    return <Component />;
  };
  return Newcomponent;
}
export default RoutGuard;
